from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-14 14:08:35.454222
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 14, Jul, 2022
Time: 14:08:40
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.7924
Nobs: 717.000 HQIC: -50.1449
Log likelihood: 8990.04 FPE: 1.33673e-22
AIC: -50.3667 Det(Omega_mle): 1.18007e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298942 0.057182 5.228 0.000
L1.Burgenland 0.104876 0.037483 2.798 0.005
L1.Kärnten -0.109280 0.019886 -5.495 0.000
L1.Niederösterreich 0.209390 0.078484 2.668 0.008
L1.Oberösterreich 0.107039 0.076630 1.397 0.162
L1.Salzburg 0.258216 0.040321 6.404 0.000
L1.Steiermark 0.044551 0.052312 0.852 0.394
L1.Tirol 0.108204 0.042438 2.550 0.011
L1.Vorarlberg -0.063434 0.036645 -1.731 0.083
L1.Wien 0.046834 0.067772 0.691 0.490
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052069 0.119610 0.435 0.663
L1.Burgenland -0.032573 0.078405 -0.415 0.678
L1.Kärnten 0.043317 0.041597 1.041 0.298
L1.Niederösterreich -0.168954 0.164169 -1.029 0.303
L1.Oberösterreich 0.418949 0.160292 2.614 0.009
L1.Salzburg 0.289114 0.084342 3.428 0.001
L1.Steiermark 0.101225 0.109425 0.925 0.355
L1.Tirol 0.312534 0.088770 3.521 0.000
L1.Vorarlberg 0.029132 0.076652 0.380 0.704
L1.Wien -0.037610 0.141762 -0.265 0.791
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188170 0.029282 6.426 0.000
L1.Burgenland 0.090370 0.019195 4.708 0.000
L1.Kärnten -0.007944 0.010184 -0.780 0.435
L1.Niederösterreich 0.264574 0.040191 6.583 0.000
L1.Oberösterreich 0.135867 0.039242 3.462 0.001
L1.Salzburg 0.045222 0.020648 2.190 0.029
L1.Steiermark 0.020441 0.026789 0.763 0.445
L1.Tirol 0.091483 0.021732 4.210 0.000
L1.Vorarlberg 0.058146 0.018766 3.099 0.002
L1.Wien 0.114799 0.034706 3.308 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111287 0.029766 3.739 0.000
L1.Burgenland 0.045290 0.019512 2.321 0.020
L1.Kärnten -0.013602 0.010352 -1.314 0.189
L1.Niederösterreich 0.190586 0.040855 4.665 0.000
L1.Oberösterreich 0.303028 0.039890 7.597 0.000
L1.Salzburg 0.107820 0.020989 5.137 0.000
L1.Steiermark 0.105060 0.027231 3.858 0.000
L1.Tirol 0.103520 0.022091 4.686 0.000
L1.Vorarlberg 0.068444 0.019075 3.588 0.000
L1.Wien -0.021989 0.035279 -0.623 0.533
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.133151 0.054050 2.463 0.014
L1.Burgenland -0.050509 0.035430 -1.426 0.154
L1.Kärnten -0.044624 0.018797 -2.374 0.018
L1.Niederösterreich 0.153963 0.074185 2.075 0.038
L1.Oberösterreich 0.138083 0.072433 1.906 0.057
L1.Salzburg 0.285982 0.038113 7.504 0.000
L1.Steiermark 0.047996 0.049447 0.971 0.332
L1.Tirol 0.167795 0.040114 4.183 0.000
L1.Vorarlberg 0.093764 0.034638 2.707 0.007
L1.Wien 0.076755 0.064060 1.198 0.231
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055321 0.043170 1.281 0.200
L1.Burgenland 0.038683 0.028298 1.367 0.172
L1.Kärnten 0.050993 0.015013 3.397 0.001
L1.Niederösterreich 0.217587 0.059253 3.672 0.000
L1.Oberösterreich 0.294175 0.057853 5.085 0.000
L1.Salzburg 0.047479 0.030441 1.560 0.119
L1.Steiermark 0.001189 0.039494 0.030 0.976
L1.Tirol 0.141949 0.032039 4.430 0.000
L1.Vorarlberg 0.072211 0.027666 2.610 0.009
L1.Wien 0.081291 0.051165 1.589 0.112
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175104 0.051578 3.395 0.001
L1.Burgenland -0.002186 0.033809 -0.065 0.948
L1.Kärnten -0.063006 0.017937 -3.513 0.000
L1.Niederösterreich -0.081841 0.070792 -1.156 0.248
L1.Oberösterreich 0.191240 0.069120 2.767 0.006
L1.Salzburg 0.059601 0.036369 1.639 0.101
L1.Steiermark 0.236352 0.047186 5.009 0.000
L1.Tirol 0.496832 0.038279 12.979 0.000
L1.Vorarlberg 0.043551 0.033054 1.318 0.188
L1.Wien -0.053145 0.061130 -0.869 0.385
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173278 0.059163 2.929 0.003
L1.Burgenland -0.008106 0.038782 -0.209 0.834
L1.Kärnten 0.064958 0.020575 3.157 0.002
L1.Niederösterreich 0.207827 0.081204 2.559 0.010
L1.Oberösterreich -0.074673 0.079286 -0.942 0.346
L1.Salzburg 0.208009 0.041718 4.986 0.000
L1.Steiermark 0.123902 0.054125 2.289 0.022
L1.Tirol 0.069557 0.043909 1.584 0.113
L1.Vorarlberg 0.117223 0.037915 3.092 0.002
L1.Wien 0.120603 0.070120 1.720 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.361986 0.034118 10.610 0.000
L1.Burgenland 0.007209 0.022364 0.322 0.747
L1.Kärnten -0.023489 0.011865 -1.980 0.048
L1.Niederösterreich 0.217127 0.046828 4.637 0.000
L1.Oberösterreich 0.199530 0.045722 4.364 0.000
L1.Salzburg 0.043216 0.024058 1.796 0.072
L1.Steiermark -0.014241 0.031213 -0.456 0.648
L1.Tirol 0.104482 0.025321 4.126 0.000
L1.Vorarlberg 0.070721 0.021864 3.235 0.001
L1.Wien 0.035491 0.040437 0.878 0.380
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038643 0.139007 0.192313 0.154329 0.115990 0.101890 0.061199 0.216372
Kärnten 0.038643 1.000000 -0.014488 0.133827 0.058183 0.095942 0.433602 -0.052561 0.095428
Niederösterreich 0.139007 -0.014488 1.000000 0.334574 0.142284 0.293867 0.092264 0.177123 0.313889
Oberösterreich 0.192313 0.133827 0.334574 1.000000 0.228054 0.324132 0.175415 0.164139 0.261351
Salzburg 0.154329 0.058183 0.142284 0.228054 1.000000 0.137821 0.119073 0.139900 0.128946
Steiermark 0.115990 0.095942 0.293867 0.324132 0.137821 1.000000 0.145321 0.135231 0.070582
Tirol 0.101890 0.433602 0.092264 0.175415 0.119073 0.145321 1.000000 0.110452 0.142385
Vorarlberg 0.061199 -0.052561 0.177123 0.164139 0.139900 0.135231 0.110452 1.000000 -0.002558
Wien 0.216372 0.095428 0.313889 0.261351 0.128946 0.070582 0.142385 -0.002558 1.000000